package com.cg.springboot.controller;

import com.cg.springboot.entity.Book;
import com.cg.springboot.entity.Result;
import com.cg.springboot.mapper.BookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: springboot->BookController
 * @author: cg
 * @create: 2022-04-27 10:38
 **/
@RestController
public class BookController {

    @Autowired
    private BookMapper bookMapper;

    @GetMapping("/getAllBook")
    @ResponseBody
    public Result getAllBook() {
        return Result.ok(bookMapper.getAllBook());
    }

    @GetMapping("/getBookById")
    @ResponseBody
    public Result getBookById(@RequestParam Integer id) {
        return Result.ok(bookMapper.getBookById(id));
    }

    @GetMapping("/deleteBookById")
    @ResponseBody
    public Result deleteBookById(@RequestParam Integer id) {
        bookMapper.deleteBookById(id);
        return Result.ok(null);
    }

    @PostMapping("/addBook")
    @ResponseBody
    public Result addBook(Book book) {
        bookMapper.insertBook(book);
        return Result.ok(null);
    }


}
